<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<head>
<title>Section 12.7.&nbsp; Cancel Options</title>
<link rel="STYLESHEET" type="text/css" href="images/style.css">
<link rel="STYLESHEET" type="text/css" href="images/docsafari.css">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch12lev1sec6.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch12lev1sec8.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
<br><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><a name="ch12lev1sec7"></a>
<h3 class="docSection1Title">12.7. Cancel Options</h3>
<p class="docText">Two thread attributes that are not included in the <tt>pthread_attr_t</tt> structure are the <span class="docEmphasis">cancelability state</span> and the <span class="docEmphasis">cancelability type</span>. These attributes affect the behavior of a thread in response to a call to <tt>pthread_cancel</tt> (<a class="docLink" href="ch11lev1sec5.html#ch11lev1sec5">Section 11.5</a>).</P>
<p class="docText">The <span class="docEmphasis">cancelability state</span> attribute can be either <tt>PTHREAD_CANCEL_ENABLE</tt> or <tt>PTHREAD_CANCEL_DISABLE</tt>. A thread can change its <span class="docEmphasis">cancelability state</span> by calling <tt>pthread_setcancelstate</tt>.</P>
<a name="inta245"></a><p><table cellspacing="0" class="allBorders" border="1" RULES="none" cellpadding="5"><colgroup><col width="500"></colgroup><thead></thead><TR><TD class="docTableCell" align="left" valign="top"><p class="docText">
<pre>
#include &lt;pthread.h&gt;

int pthread_setcancelstate(int <span class="docEmphItalicAlt">state</span>, int *<span class="docEmphItalicAlt">oldstate</span>);
</pre><BR>

</p></TD></TR><TR><td class="docTableCell" align="right" valign="top"><p class="docText">Returns: 0 if OK, error number on failure</P></td></TR></table></P><BR>
<p class="docText">In one atomic operation, <tt>pthread_setcancelstate</tt> sets the current <span class="docEmphasis">cancelability state</span> to <span class="docEmphasis">state</span> and stores the previous <span class="docEmphasis">cancelability state</span> in the memory location pointed to by <span class="docEmphasis">oldstate</span>.</p>
<p class="docText">Recall from <a class="docLink" href="ch11lev1sec5.html#ch11lev1sec5">Section 11.5</a> that a call to <tt>pthread_cancel</tt> doesn't wait for a thread to terminate. In the default case, a thread will continue to execute after a cancellation request is made, until the thread reaches a <span class="docEmphasis">cancellation point</span>. A cancellation point is a place where the thread checks to see whether it has been canceled, and then acts on the request. POSIX.1 guarantees that cancellation points will occur when a thread calls any of the functions listed in <a class="docLink" href="#ch12fig14">Figure 12.14</a>.</P>
<a name="ch12fig14"></a><P><table cellspacing="0" class="allBorders" border="1" RULES="cols" cellpadding="5"><caption><h5 class="docTableTitle">Figure 12.14. Cancellation points defined by POSIX.1</H5></caption><colgroup><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><thead></thead><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>accept</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>mq_timedsend</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putpmsg</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sigsuspend</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>aio_suspend</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>msgrcv</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pwrite</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sigtimedwait</tt>
</p></td></TR><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>clock_nanosleep</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>msgsnd</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>read</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>sigwait</tt>
</p></TD></TR><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>close</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>msync</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>readv</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sigwaitinfo</tt>
</P></td></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>connect</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>nanosleep</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>recv</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sleep</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>creat</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>open</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>recvfrom</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>system</tt>
</p></TD></TR><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fcntl2</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pause</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>recvmsg</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>tcdrain</tt>
</P></TD></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fsync</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>poll</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>select</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>usleep</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getmsg</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pread</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sem_timedwait</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>wait</tt>
</P></TD></tr><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpmsg</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_cond_timedwait</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sem_wait</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>waitid</tt>
</P></TD></tr><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>lockf</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_cond_wait</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>send</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>waitpid</tt>
</P></td></TR><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>mq_receive</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_join</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>sendmsg</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>write</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>mq_send</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_testcancel</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>sendto</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>writev</tt>
</P></TD></tr><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>mq_timedreceive</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putmsg</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>sigpause</tt></p></TD><TD class="docTableCell" align="left" valign="top">&nbsp;</td></tr></table></p><br>
<p class="docText"><a name="idd1e90899"></a><a name="idd1e90904"></a><a name="idd1e90909"></a><a name="idd1e90914"></a><a name="idd1e90919"></a><a name="idd1e90924"></a><a name="idd1e90929"></a><a name="idd1e90934"></a><a name="idd1e90939"></a><a name="idd1e90944"></a><a name="idd1e90949"></a><a name="idd1e90954"></a><a name="idd1e90959"></a><a name="idd1e90964"></a><a name="idd1e90969"></a><a name="idd1e90974"></a><a name="idd1e90979"></a><a name="idd1e90984"></a><a name="idd1e90989"></a><a name="idd1e90994"></a><a name="idd1e90999"></a><a name="idd1e91004"></a><a name="idd1e91009"></a><a name="idd1e91014"></a><a name="idd1e91019"></a><a name="idd1e91024"></a><a name="idd1e91029"></a><a name="idd1e91034"></a><a name="idd1e91041"></a><a name="idd1e91046"></a><a name="idd1e91053"></a><a name="idd1e91058"></a><a name="idd1e91063"></a><a name="idd1e91068"></a><a name="idd1e91073"></a><a name="idd1e91078"></a><a name="idd1e91083"></a><a name="idd1e91088"></a><a name="idd1e91093"></a><a name="idd1e91098"></a><a name="idd1e91103"></a><a name="idd1e91108"></a><a name="idd1e91113"></a><a name="idd1e91118"></a><a name="idd1e91123"></a><a name="idd1e91128"></a><a name="idd1e91133"></a><a name="idd1e91138"></a><a name="idd1e91143"></a><a name="idd1e91148"></a><a name="idd1e91153"></a><a name="idd1e91156"></a><a name="idd1e91161"></a><a name="idd1e91166"></a><a name="idd1e91171"></a><a name="idd1e91176"></a><a name="idd1e91181"></a><a name="idd1e91186"></a><a name="idd1e91191"></a>A thread starts with a default <span class="docEmphasis">cancelability state</span> of <tt>PTHREAD_CANCEL_ENABLE</tt>. When the state is set to <tt>PTHREAD_CANCEL_DISABLE</tt>, a call to <tt>pthread_cancel</tt> will not kill the thread. Instead, the cancellation request remains pending for the thread. When the state is enabled again, the thread will act on any pending cancellation requests at the next cancellation point.</P>
<p class="docText">In addition to the functions listed in <a class="docLink" href="#ch12fig14">Figure 12.14</a>, POSIX.1 specifies the functions listed in <a class="docLink" href="#ch12fig15">Figure 12.15</a> as optional cancellation points.</p>
<a name="ch12fig15"></a><P><table cellspacing="0" class="allBorders" border="1" RULES="cols" cellpadding="5"><caption><h5 class="docTableTitle">Figure 12.15. Optional cancellation points defined by POSIX.1</H5></caption><colgroup><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><thead></thead><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>catclose</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>ftell</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getwc</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>printf</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>catgets</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>ftello</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getwchar</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putc</tt>
</P></TD></tr><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>catopen</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>ftw</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getwd</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putc_unlocked</tt>
</p></td></tr><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>closedir</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fwprintf</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>glob</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>putchar</tt>
</p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>closelog</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fwrite</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>iconv_close</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putchar_unlocked</tt>
</p></TD></TR><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>ctermid</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fwscanf</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>iconv_open</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>puts</tt>
</p></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_close</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getc</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>ioctl</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pututxline</tt>
</P></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_delete</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getc_unlocked</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>lseek</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>putwc</tt></p></td></tr><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_fetch</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getchar</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>mkstemp</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>putwchar</tt></p></TD></tr><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_nextkey</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getchar_unlocked</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>nftw</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>readdir</tt></p></td></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_open</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getcwd</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>opendir</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>readdir_r</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>dbm_store</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getdate</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>openlog</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>remove</tt></P></td></TR><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>dlclose</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrent</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pclose</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>rename</tt></p></TD></TR><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>dlopen</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrgid</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>perror</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>rewind</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>endgrent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrgid_r</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>popen</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>rewinddir</tt></p></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>endhostent</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrnam</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_fadvise</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>scanf</tt></P></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>endnetent</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getgrnam_r</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_fallocate</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>seekdir</tt></p></TD></tr><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>endprotoent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>gethostbyaddr</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_madvise</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>semop</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>endpwent</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>gethostbyname</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_spawn</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>setgrent</tt></P></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>endservent</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>gethostent</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_spawnp</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>sethostent</tt></P></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>endutxent</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>gethostname</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_clear</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>setnetent</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fclose</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getlogin</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_close</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>setprotoent</tt></P></td></TR><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fcntl</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getlogin_r</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_create</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>setpwent</tt></P></td></TR><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fflush</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getnetbyaddr</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_create_withlog</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>setservent</tt></p></TD></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fgetc</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getnetbyname</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_eventtypelist_getnext_id</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>setutxent</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fgetpos</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getnetent</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_eventtypelist_rewind</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>strerror</tt></P></td></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fgets</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getprotobyname</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_flush</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>syslog</tt></p></td></tr><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fgetwc</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getprotobynumber</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_get_attr</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>tmpfile</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fgetws</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getprotoent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_get_filter</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>tmpnam</tt></P></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fopen</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwent</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_get_status</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>ttyname</tt></P></TD></tr><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fprintf</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwnam</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_getnext_event</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>ttyname_r</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fputc</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwnam_r</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_open</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>ungetc</tt></p></td></tr><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fputs</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwuid</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_rewind</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>ungetwc</tt></P></td></TR><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fputwc</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getpwuid_r</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_set_filter</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>unlink</tt></p></TD></tr><TR><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fputws</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>gets</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_shutdown</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>vfprintf</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fread</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getservbyname</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_trace_timedgetnext_event</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>vfwprintf</tt></P></td></TR><TR><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>freopen</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getservbyport</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>posix_typed_mem_open</tt></p></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>vprintf</tt></p></TD></TR><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fscanf</tt></p></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getservent</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_rwlock_rdlock</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>vwprintf</tt></p></td></tr><tr><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>fseek</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getutxent</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_rwlock_timedrdlock</tt></p></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>wprintf</tt></p></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fseeko</tt></P></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>getutxid</tt></P></TD><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_rwlock_timedwrlock</tt></p></TD><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>wscanf</tt></P></TD></TR><tr><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>fsetpos</tt></P></td><TD class="docTableCell" align="left" valign="top"><p class="docText"><tt>getutxline</tt></P></td><td class="docTableCell" align="left" valign="top"><p class="docText"><tt>pthread_rwlock_wrlock</tt></p></td><TD class="docTableCell" align="left" valign="top">&nbsp;</td></TR></table></p><BR>
<blockquote>
<p class="docText">Note that several of the functions listed in <a class="docLink" href="#ch12fig15">Figure 12.15</a> are not discussed further in this text. Many are optional in the Single UNIX Specification.</p>
</blockquote>
<p class="docText">If your application doesn't call one of the functions in <a class="docLink" href="#ch12fig14">Figure 12.14</a> or <a class="docLink" href="#ch12fig15">Figure 12.15</a> for a long period of time (if it is compute-bound, for example), then you can call <tt>pthread_testcancel</tt> to add your own cancellation points to the program.</p>
<a name="inta246"></a><p><table cellspacing="0" class="allBorders" border="1" RULES="none" cellpadding="5"><colgroup><col width="500"></colgroup><thead></thead><tr><td class="docTableCell" align="left" valign="top"><p class="docText">
<pre>
#include &lt;pthread.h&gt;

void pthread_testcancel(void);
</pre><br>

</p></td></tr></table></p><br>
<p class="docText">When you call <tt>pthread_testcancel</tt>, if a cancellation request is pending and if cancellation has not been disabled, the thread will be canceled. When cancellation is disabled, however, calls to <tt>pthread_testcancel</tt> have no effect.</p>
<p class="docText">The default cancellation type we have been describing is known as <span class="docEmphasis">deferred cancellation</span>. After a call to <tt>pthread_cancel</tt>, the actual cancellation doesn't occur until the thread hits a cancellation point. We can change the cancellation type by calling <tt>pthread_setcanceltype</tt>.</p>
<a name="inta250"></a><p><table cellspacing="0" class="allBorders" border="1" RULES="none" cellpadding="5"><colgroup><col width="500"></colgroup><thead></thead><tr><td class="docTableCell" align="left" valign="top"><p class="docText">
<pre>
#include &lt;pthread.h&gt;

int pthread_setcanceltype(int <span class="docEmphItalicAlt">type</span>, int *<span class="docEmphItalicAlt">oldtype</span>);
</pre><br>

</P></TD></tr><TR><TD class="docTableCell" align="right" valign="top"><p class="docText">Returns: 0 if OK, error number on failure</P></td></TR></table></P><BR>
<p class="docText"><a name="idd1e92290"></a><a name="idd1e92295"></a><a name="idd1e92300"></a><a name="idd1e92305"></a><a name="idd1e92310"></a><a name="idd1e92315"></a><a name="idd1e92320"></a><a name="idd1e92325"></a><a name="idd1e92330"></a><a name="idd1e92335"></a><a name="idd1e92340"></a><a name="idd1e92345"></a><a name="idd1e92350"></a><a name="idd1e92355"></a><a name="idd1e92360"></a><a name="idd1e92365"></a><a name="idd1e92370"></a><a name="idd1e92375"></a><a name="idd1e92380"></a><a name="idd1e92385"></a><a name="idd1e92390"></a><a name="idd1e92395"></a><a name="idd1e92400"></a><a name="idd1e92405"></a><a name="idd1e92410"></a><a name="idd1e92415"></a><a name="idd1e92420"></a><a name="idd1e92425"></a><a name="idd1e92430"></a><a name="idd1e92435"></a><a name="idd1e92440"></a><a name="idd1e92445"></a><a name="idd1e92450"></a><a name="idd1e92455"></a><a name="idd1e92460"></a><a name="idd1e92465"></a><a name="idd1e92470"></a><a name="idd1e92475"></a><a name="idd1e92480"></a><a name="idd1e92485"></a><a name="idd1e92490"></a><a name="idd1e92495"></a><a name="idd1e92500"></a><a name="idd1e92505"></a><a name="idd1e92510"></a><a name="idd1e92515"></a><a name="idd1e92520"></a><a name="idd1e92525"></a><a name="idd1e92530"></a><a name="idd1e92535"></a><a name="idd1e92540"></a><a name="idd1e92545"></a><a name="idd1e92550"></a><a name="idd1e92555"></a><a name="idd1e92560"></a><a name="idd1e92565"></a><a name="idd1e92570"></a><a name="idd1e92575"></a><a name="idd1e92580"></a><a name="idd1e92585"></a><a name="idd1e92590"></a><a name="idd1e92595"></a><a name="idd1e92600"></a><a name="idd1e92605"></a><a name="idd1e92610"></a><a name="idd1e92615"></a><a name="idd1e92620"></a><a name="idd1e92625"></a><a name="idd1e92630"></a><a name="idd1e92635"></a><a name="idd1e92640"></a><a name="idd1e92645"></a><a name="idd1e92650"></a><a name="idd1e92655"></a><a name="idd1e92660"></a><a name="idd1e92665"></a><a name="idd1e92670"></a><a name="idd1e92675"></a><a name="idd1e92680"></a><a name="idd1e92685"></a><a name="idd1e92690"></a><a name="idd1e92695"></a><a name="idd1e92700"></a><a name="idd1e92705"></a><a name="idd1e92710"></a><a name="idd1e92715"></a><a name="idd1e92720"></a><a name="idd1e92725"></a><a name="idd1e92730"></a><a name="idd1e92735"></a><a name="idd1e92740"></a><a name="idd1e92745"></a><a name="idd1e92750"></a><a name="idd1e92755"></a><a name="idd1e92760"></a><a name="idd1e92765"></a><a name="idd1e92770"></a><a name="idd1e92775"></a><a name="idd1e92780"></a><a name="idd1e92785"></a><a name="idd1e92790"></a><a name="idd1e92795"></a><a name="idd1e92800"></a><a name="idd1e92805"></a><a name="idd1e92810"></a><a name="idd1e92815"></a><a name="idd1e92820"></a><a name="idd1e92825"></a><a name="idd1e92830"></a><a name="idd1e92835"></a><a name="idd1e92840"></a><a name="idd1e92845"></a><a name="idd1e92850"></a><a name="idd1e92855"></a><a name="idd1e92860"></a><a name="idd1e92865"></a><a name="idd1e92870"></a><a name="idd1e92875"></a><a name="idd1e92880"></a><a name="idd1e92885"></a><a name="idd1e92890"></a><a name="idd1e92895"></a><a name="idd1e92900"></a><a name="idd1e92905"></a><a name="idd1e92910"></a><a name="idd1e92915"></a><a name="idd1e92920"></a><a name="idd1e92925"></a><a name="idd1e92930"></a><a name="idd1e92935"></a><a name="idd1e92940"></a><a name="idd1e92945"></a><a name="idd1e92950"></a><a name="idd1e92955"></a><a name="idd1e92960"></a><a name="idd1e92965"></a><a name="idd1e92970"></a><a name="idd1e92975"></a><a name="idd1e92980"></a><a name="idd1e92985"></a><a name="idd1e92990"></a><a name="idd1e92995"></a><a name="idd1e93000"></a><a name="idd1e93005"></a><a name="idd1e93010"></a><a name="idd1e93015"></a><a name="idd1e93020"></a><a name="idd1e93029"></a><a name="idd1e93034"></a><a name="idd1e93039"></a><a name="idd1e93044"></a><a name="idd1e93049"></a><a name="idd1e93054"></a><a name="idd1e93059"></a><a name="idd1e93064"></a><a name="idd1e93069"></a><a name="idd1e93074"></a><a name="idd1e93079"></a><a name="idd1e93084"></a><a name="idd1e93089"></a><a name="idd1e93094"></a><a name="idd1e93099"></a><a name="idd1e93104"></a><a name="idd1e93109"></a>The <span class="docEmphasis">type</span> parameter can be either <tt>PTHREAD_CANCEL_DEFERRED</tt> or <tt>PTHREAD_CANCEL_ASYNCHRONOUS</tt>. The <tt>pthread_setcanceltype</tt> function sets the cancellation type to <span class="docEmphasis">type</span> and returns the previous type in the integer pointed to by <span class="docEmphasis">oldtype</span>.</p>
<p class="docText">Asynchronous cancellation differs from deferred cancellation in that the thread can be canceled at any time. The thread doesn't necessarily need to hit a cancellation point for it to be canceled.</P>

<ul></UL></TD></TR></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td><div STYLE="MARGIN-LEFT: 0.15in;"><a href="toc.html"><img src="images/team.gif" width="60" height="17" border="0" align="absmiddle"  alt="Team BBL"></a></div></td>
<td align="right"><div STYLE="MARGIN-LEFT: 0.15in;">
<a href=ch12lev1sec6.html><img src="images/prev.gif" width="60" height="17" border="0" align="absmiddle" alt="Previous Page"></a>
<a href=ch12lev1sec8.html><img src="images/next.gif" width="60" height="17" border="0" align="absmiddle" alt="Next Page"></a>
</div></td></tr></table>
</body></html><br>
<table width="100%" cellspacing="0" cellpadding="0"
style="margin-top: 0pt; border-collapse: collapse;"> 
<tr> <td align="right" style="background-color=white; border-top: 1px solid gray;"> 
<a href="http://www.zipghost.com/" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">The CHM file was converted to HTM by Trial version of <b>ChmD<!--81-->ecompiler</b>.</a>
</TD>
</TR><tr>
<td align="right" style="background-color=white; "> 
<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target="_blank" style="font-family: Tahoma, Verdana;
 font-size: 11px; text-decoration: none;">Download <b>ChmDec<!--81-->ompiler</b> at: http://www.zipghost.com</a>
</TD></tr></table>
